package com.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThirdThread {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThirdThread rt = new ThirdThread();
        FutureTask<Integer> task = new FutureTask<>(() -> {
            int i = 0;
            for (; i < 100; i++) {
                System.out.println(Thread.currentThread().getName() + "的循环遍历i的值" + i);
            }
            return i;
        });
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() + "的循环遍历i的值" + i);
            if (i == 20) {
                new Thread(task, "有返回值的线程").start();
            }
        }
        System.out.println("子线程的返回值" + task.get());
    }

}
